//
//  ConsultViewController.m
//  A_GOGO
//
//  Created by Liuiu on 16/1/25.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "ConsultViewController.h"
#import "NetworkHandler.h"
#import "HomeModel.h"
#import <UIImageView+WebCache.h>
#import "UIColor+Wonderful.h"
#import "ConsultTableViewCell.h"
#import "ConsultTouchViewController.h"

@interface ConsultViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic ,retain)UITableView *tableView;
@property (nonatomic ,retain)NSMutableArray *arr;
@end

@implementation ConsultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor whiteColor];
    self.navigationItem.title = @"资讯中心";
    self.navigationController.navigationBar.translucent = NO;
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 90)];
    _tableView.backgroundColor = [UIColor maroonColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    [self data];
    //注册重用池
    [_tableView registerClass:[ConsultTableViewCell class] forCellReuseIdentifier:@"cell"];
    [_tableView release];
    
}
- (void)data
{
    NSString *str =@"http://api.sj.2144.cn/mobile/newapp/Newslist";
    [NetworkHandler GETWithURL:str completion:^(id result) {
      
        NSArray *arr = result[@"datas"];
        self.arr = [HomeModel modelHanderWithArray:arr];
        
        [_tableView reloadData];
        NSLog(@"%@",_arr);
    }];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _arr.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ConsultTableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

    HomeModel *m = _arr[indexPath.row];
    [cell.image sd_setImageWithURL:[NSURL URLWithString:m.image]];
    cell.title.text = m.title;
    
    if (m.type.floatValue == 2) {
        cell.type.backgroundColor =[UIColor redColor];
        cell.type.text = @"新闻";
        cell.type.textColor = [UIColor whiteColor];
    }if (m.type.floatValue == 0 ) {
        cell.type.backgroundColor = [UIColor greenColor];
        cell.type.text = @"推荐";
        cell.type.textColor = [UIColor whiteColor];
    }
    
  
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 135;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    //当离开某行时,让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ConsultTouchViewController *touch =[[ConsultTouchViewController alloc]init];
    


    
    
    
    [self.navigationController pushViewController:touch animated:YES];
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
